<?php

class Dashboard_Model extends Model {

	 function __construct(){
		parent::__construct();
		//echo 'Dashboard_Model';
	}

	function InsertData(){

		$textdata = $_POST['textdata'];
		//print_r($textdata);
		$stmt = $this->db->prepare("INSERT INTO data (textdata) VALUES (:textdata)");
		$stmt->execute(array(':textdata' => $textdata));
		$data =  array('textdata' => $textdata, 'id' => $this->db->lastInsertId());
		echo json_encode($data);
	}



	function getListings(){

		$stmt = $this->db->prepare("SELECT * FROM data ORDER BY id DESC");
		$stmt->setFetchMode(PDO::FETCH_ASSOC);
		$stmt->execute();
		$data = $stmt->fetchAll();
		echo json_encode($data);	
	}

	function deleteListings(){

		$id = $_POST['id'];
		$stmt = $this->db->prepare("DELETE FROM data WHERE id='".$id."'");
		$stmt->execute();		

	}


}